import request from "@/utils/request"
import { useCookieStore } from "@/stores/cookieStore"

// 获取用户歌单（有歌单 id，无详细歌曲）
export const getUserPlayListAPi = (id) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/user/playlist',
    params: {
      cookie: cookie,
      uid: id,
      timestamp: Date.now()
    }
  })
}

// 获取推荐歌单，不需要登录
export const getPersonalizedAPi = (limit = 30) => {
  return request({
    url: '/personalized',
    params: {
      limit
    }
  })
}

// 获取每日推荐歌单，需要登录
export const getRecommentSongListAPi = () => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/recommend/resource',
    params: {
      cookie
    }
  })
}

// 获取歌单详情
export const getPlayListDetailAPi = (id) => {
  return request({
    url: '/playlist/detail',
    params: {
      id
    }
  })
}

// 获取歌单详情动态
export const getPlayListDetailDynamicAPi = (id) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/detail/dynamic',
    params: {
      id,
      cookie
    }
  })
}

// 获取歌单内的所有歌曲
export const getUserPlayListAllAPi = (id, limit = 30, offset = 0) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/track/all',
    params: {
      id,
      limit,
      offset,
      cookie,
      timestamp: Date.now()
    }
  })
}

// 获取每日推荐歌曲
export const getRecommendSongAPi = () => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/recommend/songs',
    params: {
      cookie
    }
  })
}

// 获取推荐新歌曲
export const getNewSongAPi = (limit = 20) => {
  return request({
    url: '/personalized/newsong',
    params: {
      limit
    }
  })
}

// 获取歌曲 url
export const getSongUrlAPi = (id, level) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/song/url/v1',
    params: {
      id,
      level,
      cookie
    }
  })
}

// 收藏歌单或取消收藏歌单（1：收藏，2：取消收藏）
export const isCollectSongListAPi = (id, t) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/subscribe',
    params: {
      id,
      t,
      cookie
    }
  })
}

// 喜欢或取消喜欢音乐
export const isLikeMusicAPi = (id, type) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/like',
    params: {
      id,
      like: type,
      cookie,
      timestamp: Date.now()
    }
  })
}


// 获取精品歌单标签
export const getPlayListTagsAPi = () => {
  return request({
    url: '/playlist/highquality/tags'
  })
}

// 获取精品歌单列表
export const getRefinedPlayListAPi = (cat, limit, before) => {
  return request({
    url: '/top/playlist/highquality',
    params: {
      cat,
      limit,
      before
    }
  })
}

// 创建歌单
export const createPlayListAPi = (data) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/create',
    params: {
      name: data.name,
      type: data.type,
      privacy: data.privacy,
      cookie,
      timestamp: Date.now()
    }
  })
}

// 删除歌单
export const delectPlayListAPi = (id) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/delete',
    params: {
      id,
      cookie,
      timestamp: Date.now()
    }
  })
}

// 将歌单添加或删除歌曲
export const collcetOrDeleteSongAPi = (op, pid, tracks) => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/playlist/tracks',
    params: {
      op,
      pid,
      tracks,
      cookie,
      timestamp: Date.now()
    }
  })
}

// 获取歌词
export const getSongLyricAPi = (id) => {
  return request({
    url: '/lyric',
    params: {
      id
    }
  })
}

// 获取歌词
export const getRecentSongApi = () => {
  const cookie = useCookieStore().cookie.cookie
  return request({
    url: '/record/recent/song',
    params: {
      cookie
    }
  })
}


